package com.taijihuabao.modules.service.impl;

import com.taijihuabao.modules.entity.ApprovalEntity;
import com.taijihuabao.modules.mapper.ApprovalMapper;
import com.taijihuabao.modules.model.approval.vo.ApprovalVO;
import com.taijihuabao.modules.model.approval.dto.EndorseDTO;
import com.taijihuabao.modules.service.ApprovalService;
import org.activiti.engine.TaskService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ApprovalServiceImpl implements ApprovalService {

    @Resource
    private ApprovalMapper approvalMapper;
    @Resource
    private TaskService taskService;

    /**
     * 修改审批单
     *
     * @param approvalEntity
     */
    public void updateApproval(ApprovalEntity approvalEntity) {
        approvalMapper.updateApproval(approvalEntity);
    }

    /**
     * 给或签任务加签
     *
     * @param endorseDTO
     */
    @Override
    public void addTaskAssingnees(EndorseDTO endorseDTO) {
        String taskId = endorseDTO.getTaskId();
        List<String> userIds = endorseDTO.getUserIds();
        //循环添加审批人
        for (String assingnee : userIds) {
            taskService.addCandidateUser(taskId, assingnee);
        }
    }
}
